package com.oyjd.framework;

import java.io.File;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Environment;

/**
 * 系统环境变量
 * 
 * @author 欧建东
 * @email oyjd@163.com
 */
public class Const {

	private Const() {
	}

	public static final String APP_NAME = "ChengJiCount";// 应用英文名

	public static final String SERVER = "http://www.baidu.com";// 服务器地址

	public static final boolean LOG_FLAG = true;// 是否输出日志

	// ------------------------系统文件路径常量

	public static final String SDCARD = Environment.getExternalStorageDirectory().getPath();// SD卡路径

	public static final String APP_IMG_DIR = SDCARD + "/" + APP_NAME + "/img/";// 图片路径

	public static final String APP_APK_DIR = SDCARD + "/" + APP_NAME + "/apk/";// 安装包路径

	public static final String APP_LOG_DIR = SDCARD + "/" + APP_NAME + "/log/";// 日志输出路径

	public static final String APP_DATA_DIR = SDCARD + "/" + APP_NAME + "/data/";// 数据输出路径

	// ------------------------系统数据获取Code常量

	public static final int OK = 0;// 执行成功

	public static final int DEFAULT = -1;// 服务端返回数据异常

	public static final int ChengJiFileListActivity_code = 9001;
	public static final int ChengJiEditActivity_code = 9002;

	static {
		if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
			new File(Const.APP_IMG_DIR).mkdirs();
			new File(Const.APP_APK_DIR).mkdirs();
			new File(Const.APP_LOG_DIR).mkdirs();
			new File(Const.APP_DATA_DIR).mkdirs();
		}

	}

	/**
	 * 获取当前客户端的版本号（记录在AndroidManifest.xml的android:versionCode中）
	 */
	public static int getVersionCode(Context context) {
		int version = -1;
		try {
			PackageManager manager = context.getPackageManager();
			PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
			version = info.versionCode;
		} catch (Exception e) {
		}
		return version;
	}

	/**
	 * 获取当前客户端的版本号（记录在AndroidManifest.xml的android:versionCode中）
	 */
	public static String getVersionCodeName(Context context) {
		String version = "";
		try {
			PackageManager manager = context.getPackageManager();
			PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
			version = info.versionName;
		} catch (Exception e) {
		}
		return version;
	}

}
